package com.itheima.d8_thread_pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*
    目标：掌握线程池的创建。
    需求 : 使用线程池处理Runnable类型任务
 */
public class ThreadPoolTest2 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPool=new ThreadPoolExecutor(
                3,
                10,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(20),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()


        );
        for (int i = 0; i <= 31; i++) {
            threadPool.submit(new MyRunnable("小明"+i));
        }
        threadPool.shutdown();
    }


}

class MyRunnable implements  Runnable{
    private String name;

    public MyRunnable(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(name+"の🐓L~oγe🏀"+"--"+Thread.currentThread().getName());
    }
}
